﻿#region Using directives

using System;
using System.Collections.Generic;
using System.Text;

using Weazel.Toad.Application.Items;

#endregion

namespace Weazel.Toad.Application.Actions
{
  public class CloseFileAction : ActionBase
  {
    public CloseFileAction()
    {
      // can't enable before there is a file to close
      Enabled = false;

      Application.Instance.SelectedItemChanged +=new EventHandler<SelectedItemChangedEventArgs>(Instance_SelectedItemChanged);
    }

    public override void Execute(object sender, EventArgs e)
    {
      Application.Instance.SelectedItem.Close();
    }

    void Instance_SelectedItemChanged(object sender, SelectedItemChangedEventArgs e)
    {
      if (Application.Instance.SelectedItem is TextFile)
        Enabled = true;
      else
        Enabled = false;
    }
  }
}
